<?php
class	matiere_compte
{
	private $Ref_ID_AN;
	private $MatCompteArr = array (
	'ID_AN' => '',
	'NameCompte' => '');

	public	function	getRef_ID_AN()
	{
		return $this-> Ref_ID_AN;
	}

	public	function	setId($str)
	{
		$this->RefMatiere = $str;
	}

	public function SetMatCompteArr($arrArgs = array ())
	{
		foreach ($this -> MatCompteArr as $clef => $val)
		{
			if (array_key_exists ($clef, $arrArgs))
			{
				$this -> MatCompteArr[$clef] = $arrArgs[$clef];
			}
			else if (!empty ($val))
			{
				$this -> MatCompteArr[$clef] = $val;
			}
		}
	}

	public	function	setMatiereCompteByReferenceId($idM)
	{
		mysql_connect("localhost", "mygesco", "mygesco") or die("Impossible de se connecter : " . mysql_error());

		mysql_select_db("mygesco");
		$req = 'SELECT * FROM `matiere_compte` WHERE  `ID_AN` = "2010" ' . $idM;
		$result = mysql_query($req);

		while ($row = mysql_fetch_array($result))
		{
			$this -> SetMatCompteArr($row);
			//print_r($this -> MatCompteArr);
		}
	}

	public function __toString ()
	{
		$chaineTemp = '';
		if (isset ($this -> MatCompteArr['ID_AN']) && !empty ($this -> MatCompteArr['NameCompte']))
		{
			foreach ($this -> MatCompteArr as $key => $value)
			{
				$chaineTemp .= "$key: $value\n" . '<br />';
			}
		}
		return $chaineTemp;
	}
}


// on instancie notre objet
$mat = new matiere_compte();

$mat -> setMatiereCompteByReferenceId("");
echo $mat;


?>